package cn.itcast.wushangxiantu.BaseAdapter;


import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import cn.itcast.wushangxiantu.R;
import cn.itcast.wushangxiantu.UserData.UserPaiHang;

public class PaiHangBangAdapter extends BaseAdapter {
    private Context context;
    private UserPaiHang userPaiHang;
    int num = 0;

    public PaiHangBangAdapter(Context context) {
        this.context = context;
    }

    public UserPaiHang getUserPaiHang() {
        return userPaiHang;
    }

    public void setPaiHang(UserPaiHang userPaiHang, int num) {
        this.userPaiHang = userPaiHang;
        this.num = num;
        notifyDataSetChanged();

    }

    @Override
    public int getCount() {
        Log.v("2312312312313", userPaiHang.getPaiHang().size() + "");
        return userPaiHang.getPaiHang().size();
    }

    @Override
    public Object getItem(int i) {
        return userPaiHang.getPaiHang().get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = View.inflate(context, R.layout.adapter_jiaoyisuo_wodeshangjia, null);
        ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.tvName.setText("榜" + (i + 1)  );
        viewHolder.tvNumber.setText(userPaiHang.getPaiHang().get(i).getName());
        viewHolder.tvPrice.setText("等级：" + userPaiHang.getPaiHang().get(i).getDj());
        if (num == 0) {
            viewHolder.tvTime.setText("修为值：" + (userPaiHang.getPaiHang().get(i).getDj() * userPaiHang.getPaiHang().get(i).getDj() * userPaiHang.getPaiHang().get(i).getDj()  * 4 + (userPaiHang.getPaiHang().get(i).getJy() / 1000)));
        } else {
            viewHolder.tvTime.setText("金钱:" + userPaiHang.getPaiHang().get(i).getMoney());
        }
        return view;
    }


    class ViewHolder {
        public View rootView;
        public TextView tvName;
        public TextView tvNumber;
        public TextView tvPrice;
        public TextView tvTime;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.tvName = (TextView) rootView.findViewById(R.id.tvName);
            this.tvNumber = (TextView) rootView.findViewById(R.id.tvNumber);
            this.tvPrice = (TextView) rootView.findViewById(R.id.tvPrice);
            this.tvTime = (TextView) rootView.findViewById(R.id.tvTime);
        }

    }
}
